import axios from "axios";

axios.defaults.withCredentials = true;

const instance = axios.create({
  baseURL: process.env.VUE_APP_SERVICE_URL,
  timeout: process.env.VUE_APP_TIMEOUT
});

// 请求拦截器
instance.interceptors.request.use(
  config => {
    // Do something before request is sent
    console.log("请求拦截器.....");
    return config;
  },
  function(error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// 响应拦截器
instance.interceptors.response.use(
  response => {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    console.log("响应拦截器.....", response.data);
    return response;
  },
  error => {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  }
);

export default instance;
